#include "Common.hpp"
#include "ShareMemory.hpp"
#include "Fifo.hpp"

int main()
{
    share_mem.GetShm();
    share_mem.AttachShm();

    fifo.OpenForWrite();
    void *addr = share_mem.GetAddr();

    std::cout << "pos 1" << std::endl;

    // struct Data *image = new Data;

    //直接指向共享内存，向共享内存中写入
    struct Data *image = (struct Data *)addr;
    std::cout << "pos 2" << std::endl;

    while (true)
    {
        // memcpy(buffer,addr,sizeof(buffer));
        // std::cout<<"server:"<<buffer<<std::endl;
        
        strcpy(image->status, "最新");
        std::cout << "pos 3" << std::endl;
        strcpy(image->lasttime, GetCurrentTime().c_str());
        std::cout << "pos 4" << std::endl;
        strcpy(image->image, "***********");

        // printf("status: %s\n", image->status);
        // printf("lasttime: %s\n", image->lasttime);
        // printf("image: %s\n", image->image);
        // memcpy(addr,image,sizeof(image)); //sizeof(image)是指针大小
        // memcpy(addr, image, sizeof(Data));
        fifo.Sginal();
        sleep(1);
    }

    share_mem.DetachShm();
    share_mem.DeleteShm();

    return 0;
}